import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions

from BasePage.BasePage import BasePage
from Page.goods_list import GoodsList


class PutGoods(BasePage):
    __goods_num = (By.CSS_SELECTOR, '.el-form>div:nth-child(1) .el-input__inner')
    __goods_name = (By.CSS_SELECTOR, '.el-form>div:nth-child(2) .el-input__inner')
    __put_goods = (By.XPATH, "//*[text()='上架']")

    @allure.step('添加商品')
    def put_goods(self, num='something1', name='something1'):
        # 等待
        self.wait(expected_conditions.element_to_be_clickable(self.__goods_num))
        # 输入编号
        self.find_ele(self.__goods_num).send_keys(num)
        # 输入名称
        self.find_ele(self.__goods_name).send_keys(name)
        # 点击上架
        self.find_ele(self.__put_goods).click()
        return GoodsList(self.driver)
